package com.wtc.interface_;

public class InterfacePolyArray {
    public static void main(String[] args) {
        //多态数组 -> 接口类型数组
        Usb[] usb = new Usb[2];
        usb[0] = new Phone();
        usb[1] = new Camera();
        for (int i = 0; i < usb.length; i++) {
            usb[i].work();
            if (usb[i] instanceof Phone) {
                ((Phone) usb[i]).call();
            }
        }
    }
}
interface Usb {
    void work();
}
class Phone implements Usb {
    public void call() {
        System.out.println("手机正在打电话！");
    }
    @Override
    public void work() {
        System.out.println("手机正在使用！");
    }
}
class Camera implements Usb {
    @Override
    public void work() {
        System.out.println("相机正在工作！");
    }
}
